package com.iterator.controller.web.userManager;



import com.iterator.service.web.userManager.UserService;

import com.iterator.bean.web.lyh.bo.*;
import com.iterator.bean.web.lyh.utils.BaseRespVO;
import com.iterator.bean.web.lyh.utils.DataTotalItemsVO;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 用户管理
 */
@RestController
@RequestMapping("admin")
public class UserController {

    @Autowired
    UserService userService;

    //会员管理模块
    @RequestMapping("user/list")
    @RequiresPermissions("admin:user:list")
    public BaseRespVO userList(UserListBO listBO) {
        DataTotalItemsVO dataTotalItemsVO = userService.userList(listBO);
        return BaseRespVO.ok(dataTotalItemsVO);
    }

    //收货地址模块
    @RequestMapping("address/list")
    @RequiresPermissions("admin:address:list")
    public BaseRespVO addressList(@Valid AddressListBO listBO, BindingResult result) {
        if (result.hasFieldErrors()){
            return BaseRespVO.fail("参数错误！");
        }
        DataTotalItemsVO dataTotalItemsVO = userService.addressList(listBO);
        return BaseRespVO.ok(dataTotalItemsVO);
    }

    //会员收藏模块
    @RequestMapping("collect/list")
    @RequiresPermissions("admin:collect:list")
    public BaseRespVO collectList(@Valid CollectListBO listBO, BindingResult result) {
        if (result.hasFieldErrors()){
            return BaseRespVO.fail("参数错误！");
        }
        DataTotalItemsVO dataTotalItemsVO = userService.collectList(listBO);
        return BaseRespVO.ok(dataTotalItemsVO);
    }

    //会员足迹模块
    @RequestMapping("footprint/list")
    @RequiresPermissions("admin:footprint:list")
    public BaseRespVO footprintList(@Valid FootprintListBO listBO, BindingResult result) {
        if (result.hasFieldErrors()){
            return BaseRespVO.fail("参数错误！");
        }
        DataTotalItemsVO dataTotalItemsVO = userService.footprintList(listBO);
        return BaseRespVO.ok(dataTotalItemsVO);
    }

    //搜索历史模块
    @RequestMapping("history/list")
    @RequiresPermissions("admin:history:list")
    public BaseRespVO list(@Valid HistoryListBO listBO, BindingResult result) {
        if (result.hasFieldErrors()){
            return BaseRespVO.fail("参数错误！");
        }
        DataTotalItemsVO dataTotalItemsVO = userService.historyList(listBO);
        return BaseRespVO.ok(dataTotalItemsVO);
    }

    //意见反馈模块
    @RequestMapping("feedback/list")
    @RequiresPermissions("admin:feedback:list")
    public BaseRespVO list(@Valid FeedbackListBO listBO, BindingResult result) {
        if (result.hasFieldErrors()){
            return BaseRespVO.fail("参数错误！");
        }
        DataTotalItemsVO dataTotalItemsVO = userService.feedbackList(listBO);
        return BaseRespVO.ok(dataTotalItemsVO);
    }
}
